package card

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/card"
    cardReq "github.com/flipped-aurora/gin-vue-admin/server/model/card/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type CasCardsApi struct {}



// CreateCasCards 创建casCards表
// @Tags CasCards
// @Summary 创建casCards表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body card.CasCards true "创建casCards表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /casCards/createCasCards [post]
func (casCardsApi *CasCardsApi) CreateCasCards(c *gin.Context) {
	var casCards card.CasCards
	err := c.ShouldBindJSON(&casCards)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casCardsService.CreateCasCards(&casCards)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteCasCards 删除casCards表
// @Tags CasCards
// @Summary 删除casCards表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body card.CasCards true "删除casCards表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /casCards/deleteCasCards [delete]
func (casCardsApi *CasCardsApi) DeleteCasCards(c *gin.Context) {
	ID := c.Query("ID")
	err := casCardsService.DeleteCasCards(ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteCasCardsByIds 批量删除casCards表
// @Tags CasCards
// @Summary 批量删除casCards表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /casCards/deleteCasCardsByIds [delete]
func (casCardsApi *CasCardsApi) DeleteCasCardsByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := casCardsService.DeleteCasCardsByIds(IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateCasCards 更新casCards表
// @Tags CasCards
// @Summary 更新casCards表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body card.CasCards true "更新casCards表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /casCards/updateCasCards [put]
func (casCardsApi *CasCardsApi) UpdateCasCards(c *gin.Context) {
	var casCards card.CasCards
	err := c.ShouldBindJSON(&casCards)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = casCardsService.UpdateCasCards(casCards)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindCasCards 用id查询casCards表
// @Tags CasCards
// @Summary 用id查询casCards表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query card.CasCards true "用id查询casCards表"
// @Success 200 {object} response.Response{data=card.CasCards,msg=string} "查询成功"
// @Router /casCards/findCasCards [get]
func (casCardsApi *CasCardsApi) FindCasCards(c *gin.Context) {
	ID := c.Query("ID")
	recasCards, err := casCardsService.GetCasCards(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(recasCards, c)
}
// GetCasCardsList 分页获取casCards表列表
// @Tags CasCards
// @Summary 分页获取casCards表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query cardReq.CasCardsSearch true "分页获取casCards表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /casCards/getCasCardsList [get]
func (casCardsApi *CasCardsApi) GetCasCardsList(c *gin.Context) {
	var pageInfo cardReq.CasCardsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := casCardsService.GetCasCardsInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}
// GetCasCardsDataSource 获取CasCards的数据源
// @Tags CasCards
// @Summary 获取CasCards的数据源
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
// @Router /casCards/getCasCardsDataSource [get]
func (casCardsApi *CasCardsApi) GetCasCardsDataSource(c *gin.Context) {
    // 此接口为获取数据源定义的数据
    dataSource, err := casCardsService.GetCasCardsDataSource()
    if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
   		response.FailWithMessage("查询失败:" + err.Error(), c)
   		return
    }
   response.OkWithData(dataSource, c)
}

// GetCasCardsPublic 不需要鉴权的casCards表接口
// @Tags CasCards
// @Summary 不需要鉴权的casCards表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /casCards/getCasCardsPublic [get]
func (casCardsApi *CasCardsApi) GetCasCardsPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    casCardsService.GetCasCardsPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的casCards表接口信息",
    }, "获取成功", c)
}
